namespace Maple.Branch.IdentityServer
{
    using EfCoreConfigurations;
    using EfCoreRepositories;
    using Entities;
    using Extensions;
    using Microsoft.Extensions.DependencyInjection;
    using Volo.Abp.EntityFrameworkCore;
    using Volo.Abp.Modularity;

    [DependsOn(typeof(IdentityServerDomainModule),
        typeof(AbpEntityFrameworkCoreModule))]
    public class IdentityServerEfCoreModule : AbpModule
    {
        public override void PreConfigureServices(ServiceConfigurationContext context)
        {
            context.Services.PreConfigure<IIdentityServerBuilder>(
                builder =>
                {
                    builder.AddBranchStores();
                }
            );
        }

        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            context.Services.AddAbpDbContext<IdentityServerDbContext>(options =>
            {
                options.AddDefaultRepositories<IIdentityServerDbContext>();

                options.AddRepository<Client, ClientRepository>();
                options.AddRepository<ApiResource, ApiResourceRepository>();
                options.AddRepository<IdentityResource, IdentityResourceRepository>();
                options.AddRepository<PersistedGrant, PersistentGrantRepository>();
                options.AddRepository<DeviceFlowCode, DeviceFlowCodeRepository>();
            });
        }
    }
}
